<?xml version="1.0" encoding="windows-1255" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
	<script type="text/javascript" language="javascript">
	function foo()
	{
		document.getElementById("hiddenForm").style.visibility = 'visible';

		//		var divVar = document.getElementById("test");
//		divVar.innerHTML = "<form>You clicked on me?";	
	}
	function changeIsAdmin(form)
	{
		var value =form.isAdmin.options[form.isAdmin.selectedIndex].value; 
		if (value == 'yes')
		{
			document.getElementById("adPass").style.visibility = 'visible';
		}
		else
		{
			//form.adPass.style.visibility = 'hidden';
			document.getElementById("adPass").style.visibility = 'hidden';
		}
	}
	var xmlHttp = new XMLHttpRequest();
	function createUser(form){
		var email = form.email.value;
		var password = form.password.value;
		var rePassword = form.rePassword.value;
		var firstName = form.firstName.value;
		var lastName = form.lastName.value;
		//var isAdmin = form.isAdmin.value;

		var params = "email=" + email + "&password=" + password + "&rePassword=" + rePassword + 
		"&adminPassword=stub" + "&firstName=" + firstName + "&lastName=" + lastName;
	
		alert(params);
		xmlHttp.open("GET","createUser?" + params, false);
		//alert("after open");
		xmlHttp.send(null);
		alert("after send");
		xmlHttp.onreadystatechange = postUserResult();               	
		alert("after func");
	}
	
	function postUserResult(){
		var resDiv = document.getElementById("hiddenForm");
		alert(xmlHttp.readyState);//TODO: debug
		if (xmlHttp.readyState == 4){
       		resDiv.innerHTML = xmlHttp.responseText;
       	}
       	else{
       		resDiv.innerHTML = "<p>Loading...</p>";
       	}
    }	
	
	</script>
	<title>Code Sharing start page</title>
</head>
<body>
<fieldset><legend align="center">Sign in</legend>
	<form method="post" action="login">
		<input type="submit" value="Sign in as guest" />
	</form>
	<form method="post" action="login">
	<table>
		<tr>
			<td>Email: </td>
			<td><input name="email" type="text" size="15" maxlength="128" /></td>
			<td class="required"><font color="red">*</font></td>
		</tr>
		<tr>
			<td>Password: </td>
			<td><input name="password" type="password" size="15" maxlength="14" /></td>
			<td class="required"><font color="red">*</font></td>
		</tr>
	</table>
	<input type="submit" value="Sign in" />
</form>
</fieldset>
<button onclick="foo()">Create account</button>

<div id="hiddenForm" style="visibility: hidden;">
	<form method="post" action="createUser">
		<fieldset><legend align="center">User information</legend>
			<table>
				<tr>
					<td>Email: </td>
					<td><input name="email" type="text" size="15" maxlength="128" /></td>
					<td class="required"><font color="red">*</font></td>
				</tr>
				<tr>
					<td>Password: </td>
					<td><input name="password" type="password" size="15" maxlength="14" /></td>
					<td class="required"><font color="red">*</font></td>
				</tr>
				<tr>
					<td>Re-enter Password: </td>
					<td><input name="rePassword" type="password" size="15" maxlength="14" /></td>
					<td class="required"><font color="red">*</font></td>
				</tr>
				<tr>
					<td>Administrator account: </td>
					<td>
						<select name="isAdmin" onchange="changeIsAdmin(this.form)">
							<option value="no">No</option>
							<option value="yes">Yes</option>
						</select>
						<input name="adminPassword" type="password" size="15" maxlength="14" id="adPass" style="visibility: hidden;" />
						<font color="red">*</font>
					</td>
				</tr>
			</table>
			<p>fields marked with <font color="red">*</font> are required</p>
		</fieldset>
		<fieldset><legend align="center">Personal information</legend>
			<table>
				<tr>
					<td>First name: </td>
					<td><input name="firstName" type="text" size="15" maxlength="14" /></td>
				</tr>
				<tr>
					<td>Last name: </td>
					<td><input name="lastName" type="text" size="15" maxlength="14" /></td>
				</tr>
			</table>
		</fieldset>
		<input type="button" name="create" onclick="createUser(this.form)" value="send details" />
		<input type="reset" value="clear form" />
		<input type="submit" name="submit" value="hidden" style="visibility: hidden;" />
	</form>
</div>

<div id="test" />
</body>
</html>